<?php
/* @var $this AlbumController */
/* @var $model CmpCat */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'cmp-cat-form',
	'enableAjaxValidation'=>false,
	'action'=>($model->isNewRecord)?$this->pre_module_url."/album/create":"",
)); ?>

	<?php echo $form->errorSummary($model); ?>

<div class="photo_upload bd_db ">
	<ul class="form_list form_list2">
		<li class="img">
			<?php echo CHtml::image(empty($model->photo->zat_url)?'/images/upload_img.jpg':$model->photo->zat_url,'',array('id'=>'img1'))?>		
		</li>
		<?php if($model->isNewRecord){?>
		<li><span class="tit"></span>
			<?php echo CHtml::link('上传图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b>'.CHtml::fileField('image','',array('id'=>'uploadimg1','multiple'=>true)),'javascript:',array('class'=>'mem_bgx link_btn filelink mr20','onclick'=>"uploadimg('1')"))?>
			<?php echo $form->hiddenField($model,'zat_id',array('id'=>'proimage1'))?>
		</li>
		<?php }?>
		<li class="c_f"><span class="tit">所属分类：</span>
			<div class="cont f_l">
				<?php echo $form->dropDownList($model,'zpc_id',CmpCat::model()->getCmpCat('选择相册',3),array('class'=>'s_ipt w_120'))?>
				<span id="Albums_zpc_idTip"></span>
			</div>
		</li>
		<li class="c_f"><span class="tit">图片标题：</span>
			<div class="cont f_l">
				<?php echo $form->textField($model,'zal_title',array('class'=>'t_ipt w_300 text_title','maxlength'=>'30'))?><span>还能输入<strong class="c_green3">30</strong>中文字</span>
				<span id="Albums_zal_titleTip"></span>
			</div>
		</li>
		<li class="c_f"><span class="tit">图片描述：</span>
			<div class="cont f_l">
				</textarea><?php echo $form->textArea($model,'zal_desc',array('class'=>'t_area'))?>
			</div>
		</li>
		<?php if(!$model->isNewRecord){?>
		<li class="c_f"><span class="tit">替换图片：</span>
			<?php echo CHtml::link('选择图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b>'.CHtml::fileField('image','',array('id'=>'uploadimg1','multiple'=>true)),'javascript:',array('class'=>'mem_bgx link_btn filelink mr20','onclick'=>"replace('1')"))?>
			<?php echo $form->hiddenField($model,'zat_id',array('id'=>'proimage1'))?>
		</li>
		<?php }?>
		<li class="c_f"><span class="tit">&nbsp;</span>
			<div class="cont f_l">
				<?php echo CHtml::submitButton(Yii::t('cmp','Save'),array('class'=>'mem_btn mem_btn18'))?>
			</div>
		</li>
	</ul>
</div>
	
<?php $this->endWidget(); ?>

</div><!-- form -->

<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.ui.widget.js"></script>  
<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.iframe-transport.js"></script>  
<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.fileupload.js"></script>  

<script>  
//上传图片
function uploadimg (id) {
	   $('#uploadimg'+id).fileupload({         	
	        dataType: 'json',       
	        url: '/Attachment/GetAjax',   
	        success: function (json) {
	               if(json.upfile.errors=='1'){
	               		alert(json.upfile.msg);
	               }else if(json.upfile.errors=='2'){
	               		alert(json.upfile.msg);
	               }else{
		                 //修改按钮图标
		            	 $('#img'+id).attr('src',json.upfile.file);
						 //修改隐藏域值
	               		 $('#proimage'+id).attr('value',json.upfile.zat_id);
	               } 	
	        }
	    });
};

//上传图片
function replace(id) {
	   $('#uploadimg'+id).fileupload({         	
	        dataType: 'json',       
	        url: '/Attachment/Replace/id/<?php echo $model->zat_id?>',        
	        success: function (json) {
	               if(json.upfile.errors=='1'){
	               		alert(json.upfile.msg);
	               }else if(json.upfile.errors=='2'){
	               		alert(json.upfile.msg);
	               }else{
		                 //修改按钮图标
		            	 $('#img'+id).attr('src',json.upfile.file);
						 //修改隐藏域值
	               		 $('#proimage'+id).attr('value',json.upfile.zat_id);
	               } 	
	        }
	    });
};

//输入标题，字数统计
$('.text_title').bind('change',function(){
	var text = $(this).val().length;
	$(this).next('span').html('还能输入<strong class="c_green3">'+(30-text)+'</strong>中文字');
})
</script>

 <!-- 表单验证 -->
 <script type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/formvalidata/formValidator-4.1.1.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/formvalidata/formValidatorRegex.js"></script>
 <script>
	jQuery(document).ready(function($) {
		$.formValidator.initConfig({theme:"126",formID:"cmp-cat-form",
			onError:function(msg, obj){
						alert(msg);
						return false;
					},
			onsuccess:function(){ return true; }
		});
	})
</script>
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/formvalidata/cmpValidate.js"></script> 